// 报修相关API
const baseUrl = 'http://localhost:8081'; // 后端接口地址

// 新增报修
export const addFaultReport = (data) => {
	return new Promise((resolve, reject) => {
		// 模拟新增报修请求
		setTimeout(() => {
			resolve({
				code: 200,
				message: '报修提交成功',
				data: {
					reportNo: 'RPT' + Date.now()
				}
			});
		}, 1000);
	});
};

// 查询报修列表
export const getFaultReportList = (params) => {
	return new Promise((resolve) => {
		// 模拟查询报修列表
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					rows: [
						{
							reportNo: 'RPT001',
							assetNo: 'kSIWJW1231231',
							assetName: '设备',
							location: '空调一部',
							reporter: '杨文浩',
							faultTypeName: '机械故障',
							urgencyName: '紧急',
							statusName: '待派单',
							occurTime: '2021-03-23 14:53:32',
							createTime: '2021-03-23 14:53:32'
						}
					],
					total: 1
				}
			});
		}, 500);
	});
};

// 获取报修详情
export const getFaultReportDetail = (reportNo) => {
	return new Promise((resolve) => {
		// 模拟获取报修详情
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					reportNo: reportNo,
					assetNo: 'kSIWJW1231231',
					assetName: '设备',
					location: '空调一部',
					reporter: '杨文浩',
					faultTypeName: '机械故障',
					urgencyName: '紧急',
					statusName: '待派单',
					faultDescription: '设备出现异常噪音',
					occurTime: '2021-03-23 14:53:32',
					createTime: '2021-03-23 14:53:32'
				}
			});
		}, 500);
	});
};

// 获取报修类型列表
export const getReportTypeList = () => {
	return new Promise((resolve) => {
		// 模拟获取报修类型
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					rows: [
						{ code: 'REPORT_001', name: '设备故障' },
						{ code: 'REPORT_002', name: '预防性维护' },
						{ code: 'REPORT_003', name: '定期检查' }
					]
				}
			});
		}, 300);
	});
};

// 获取故障类型列表
export const getFaultTypeList = () => {
	return new Promise((resolve) => {
		// 模拟获取故障类型
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					rows: [
						{ code: 'FAULT_001', name: '机械故障' },
						{ code: 'FAULT_002', name: '电气故障' },
						{ code: 'FAULT_003', name: '液压故障' },
						{ code: 'FAULT_004', name: '气动故障' }
					]
				}
			});
		}, 300);
	});
};

// 获取紧急程度列表
export const getUrgencyLevelList = () => {
	return new Promise((resolve) => {
		// 模拟获取紧急程度
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					rows: [
						{ code: 'URGENT_001', name: '紧急', color: '#FF0000' },
						{ code: 'URGENT_002', name: '高', color: '#FF6600' },
						{ code: 'URGENT_003', name: '中', color: '#FFAA00' },
						{ code: 'URGENT_004', name: '低', color: '#00AA00' }
					]
				}
			});
		}, 300);
	});
};

// 获取设备类型列表
export const getEquipmentTypeList = () => {
	return new Promise((resolve) => {
		// 模拟获取设备类型
		setTimeout(() => {
			resolve({
				code: 200,
				data: {
					rows: [
						{ code: 'EQUIPMENT', name: '设备' },
						{ code: 'FACILITY', name: '设施' },
						{ code: 'TOOL', name: '工具' }
					]
				}
			});
		}, 300);
	});
};

// 检查设备是否有未完成的报修
export const checkUnfinishedReport = (assetNo) => {
	return new Promise((resolve) => {
		// 模拟检查未完成报修
		setTimeout(() => {
			resolve({
				code: 200,
				data: false // 没有未完成的报修
			});
		}, 300);
	});
};

// 提交报修（生成维修单）
export const submitFaultReport = (reportNo) => {
	return new Promise((resolve) => {
		// 模拟提交报修
		setTimeout(() => {
			resolve({
				code: 200,
				message: '报修提交成功'
			});
		}, 1000);
	});
};

// 撤回报修
export const withdrawFaultReport = (reportNo) => {
	return new Promise((resolve) => {
		// 模拟撤回报修
		setTimeout(() => {
			resolve({
				code: 200,
				message: '报修撤回成功'
			});
		}, 1000);
	});
};
